package com.xmut.mall.member.controller;

import com.xmut.mall.member.annotation.CheckJwt;
import com.xmut.mall.member.dto.EvaluationQueryParams;
import com.xmut.mall.member.dto.MemberEvaluationDTO;
import com.xmut.mall.member.dto.MemberEvaluationReplyDto;
import com.xmut.mall.member.service.MemberEvaluationService;
import com.xmut.mall.member.utils.RespBean;
import com.xmut.mall.member.vo.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("member/membermvaluation")
public class MemberEvaluationController {
    @Autowired
    private MemberEvaluationService memberEvaluationService;

    /**
     * 获取评论数量
     * @param id
     * @return
     */
    @CheckJwt
    @GetMapping("/getEvaluationNumber/{id}")
    public RespBean getEvaluationNumber(@PathVariable Long id){
        return memberEvaluationService.getEvaluationNumber(id);
    }

    @CheckJwt
    @DeleteMapping("/delete/{id}")
    public RespBean delete(@PathVariable Long id){
        boolean b = memberEvaluationService.removeById(id);
        if (b){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }

    /**
     * 修改评价状态
     * @param params
     * @return
     */
    @CheckJwt
    @PutMapping("/updateStatus")
    public RespBean updateStatus(@RequestBody Map<String,Object> params){
        return memberEvaluationService.updateStatus(params);
    }

    /**
     * 回复评论
     * @param dto
     * @return
     */
    @CheckJwt
    @PostMapping("/replyEvaluation")
    public RespBean replyEvaluation(@RequestBody MemberEvaluationReplyDto dto){
        return memberEvaluationService.replyEvaluation(dto);
    }

    /**
     * 根据评论ID获取评论详情
     * @param id
     * @return
     */
    @CheckJwt
    @GetMapping("/getEvaluationDetailById/{id}")
    public RespBean getEvaluationDetailById(@PathVariable Long id){
        return memberEvaluationService.getEvaluationDetailById(id);
    }

    /**
     * 获取评论的分页数据
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getEvaluationPage")
    public RespBean getEvaluationPage(@RequestBody EvaluationQueryParams params){
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(params,vo);
        return memberEvaluationService.getEvaluationPage(vo,params);
    }

    /**
     * 会员商品进行评价
     * @param dto
     * @return
     */
    @CheckJwt
    @PostMapping("/addMemberEvaluation")
    public RespBean addMemberEvaluation(@RequestBody MemberEvaluationDTO dto){
        return memberEvaluationService.addMemberEvaluation(dto);
    }
}
